<!--银行设置-->
<template>
  <div class="app-container">
    <el-form
      ref="mainForm"
      :model="formData"
      :rules="rules"
      size="mini"
      class="editForm"
      label-width="80px"
    >
      <!--表单项-->
      <el-row>
        <el-col :span="8">
          <el-form-item label="合同用时" prop="contractTime" class="car-form-item">
            <el-input v-model="formData.contractTime" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="车资用时" prop="fareTime" class="car-form-item">
            <el-input v-model="formData.fareTime" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="抵押用时" prop="mortgageTime" class="car-form-item">
            <el-input v-model="formData.mortgageTime" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="合同时效" prop="contractPrescription" class="car-form-item">
            <el-input v-model="formData.contractPrescription" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="车资时效" prop="farePrescription" class="car-form-item">
            <el-input v-model="formData.farePrescription" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="抵押时效" prop="mortgagePrescription" class="car-form-item">
            <el-input v-model="formData.mortgagePrescription" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="合同超期" prop="contractOverdue" class="car-form-item">
            <el-input v-model="formData.contractOverdue" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="车资超期" prop="fareOverdue" class="car-form-item">
            <el-input v-model="formData.fareOverdue" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="抵押超期" prop="mortgageOverdue" class="car-form-item">
            <el-input v-model="formData.mortgageOverdue" class="car-modal-col" type="number" placeholder="请输入" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="newDialog = false;$refs['mainForm'].resetFields();">重置</el-button>
      <el-button type="primary" @click="addData()">保存</el-button>
    </div>
  </div>
</template>

<style lang="scss" scoped>
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }
  .dialog-footer{
    text-align: center;
  }
  .car-modal-col{
    width: 280px;
  }
</style>

<script>

export default {
  data() {
    return {
      rules: {
        name: [
          {required: true, trigger: 'blur'}
        ]
      }, // 表单校验规则
      newDialog: false, // 添加弹框
      formData: {}, // 添加表单
      listQuery: {},
      appId:''
    }
  },
  computed: {
  },
  created() {
    this.appId = sessionStorage.getItem("appId");
    this.initDatabase()
  },
  methods: {
    /**
     * 初始化数据
     * @date 2021-05-10
     */
    async initDatabase() {
      let param = {appId: await sessionStorage.getItem("appId")};
      let data = await this.$http.post('/auth/prescriptionSetting/list/1/10', param);
      if (data.code === 200) {
        if(data.data.length >= 1) {
          this.formData = data.data[0];
          console.log(this.formData)
        }
      } else {
        this.$message({
          type: 'error',
          message: '查询失败，请刷新页面'
        });
      }
    },
    /**
     * 新增操作
     * @date 2021-05-08
     */
    async addData() {
      this.$refs['mainForm'].validate(async (valid) => {
        if (valid) {
          if (this.formData.id) {
            let data = await this.$http.post('/auth/prescriptionSetting/update', this.formData)
            console.log(data);
            if (data.code === 200) {
              this.$message({
                type: 'success',
                message: '更新成功!'
              });
            } else {
              this.$message({
                type: 'info',
                message: '操作失败，请重试'
              });
            }
          } else {
            this.formData.appId = this.appId;
            let data = await this.$http.post('/auth/prescriptionSetting/save', this.formData)
            console.log(data);
            if (data.code === 200) {
              this.$message({
                type: 'success',
                message: '保存成功!'
              });
            } else {
              this.$message({
                type: 'info',
                message: '操作失败，请重试'
              });
            }
          }
        }
      })
    }
  }
}
</script>
